﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace IceTea.Domain
{
    public class SecurityHelper
    {
        /// <summary>
        /// Hash the readable password with MD5 algorithm
        /// </summary>
        /// <param name="plainPassword"></param>
        /// <returns></returns>
        public static string HashPassword(string plainPassword)
        {
            var md5 = new MD5CryptoServiceProvider();
            md5.ComputeHash(Encoding.ASCII.GetBytes(plainPassword));
            StringBuilder hashstr = new StringBuilder();
            for (int i = 0; i < md5.Hash.Length; i++)
            {
                hashstr.Append(md5.Hash[i].ToString("x2"));
            }
            return hashstr.ToString();
        }

        public static bool VerifyPassword(string password)
        {
            if (string.IsNullOrEmpty(password) || password.Length < 6)
                return false;

            return true;
        }
    }
}
